package cn.zjj.basic.service.impl;

import cn.zjj.basic.mapper.BaseMapper;
import cn.zjj.basic.query.BaseQuery;
import cn.zjj.basic.service.IBaseService;
import cn.zjj.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T>{

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public T selectById(Long id) {

        return baseMapper.selectById(id);
    }


    @Transactional
    @Override
    public void insert(T t) {
        baseMapper.insert(t);
    }
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public PageList<T> selectQuery(BaseQuery query) {
        //总条数
        Integer count=baseMapper.count(query);

        //根据当前页和当前页条数查询 分页数据
        List<T> data = baseMapper.pageData(query);

        return new PageList<>(count,data);
    }

    @Transactional
    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }

    @Override
    public void patchInsert(List<T> t) {
        baseMapper.patchInsert(t);
    }
}
